'''
Created on 2012-1-31

@author: xiaokan
'''

class Tag(object):
    '''
    The model of HTML Tags which used in the HTMLParser to build the tree
    '''
    def __init__(self):
        self.tag_name = ''      #Tag name
        self.tag_attr = []      #Tag attributes
        self.tag_data = []      #Data in this tag
        self.sub_tags = []      #Sub tags in this tag
        self.parent_tag = None  #Parent tag in the tag tree
        
    def get_subtags_by_tag_name(self, _tag_name):
        ret = []
        for _tag in self.sub_tags:
            if _tag.tag_name == _tag_name:
                ret.append(_tag)
        return ret
    
    def get_attr_by_name(self, attr_name):
        for name, value in self.tag_attr:
            if name == attr_name:
                return value
        return ''
        

class Page(object):
    '''
    The model of Pages which used in crawling 
    '''
    def __init__(self):
        self.addr = ''      #Address of the page
        self.depth = 0      #Depth of the page in the crawling queue
        self.links = []     #Links contained in the page
        self.data = ''        #The HTML of this page
        self.length = 0
